Solved

duplication insert into SQL

Posted on 2013-02-06
3
289 Views
Last Modified: 2013-02-06
Hay im getting error with line 40 can i get some help its to stop dupication incert into SQL

<?php 

// Read values from form using $_POST (safest) 


$fname=$_POST["vname"]; 


// Connect to server 
// Replace username and password by your details  

$db = @mysql_connect("localhost","root","iqonr301"); 
if (!$db) 
{ 
        do_error("Could not connect to the server"); 
} 


// Connect to the database 
// Note that your database will be called username 

@mysql_select_db("test",$db)or do_error("Could not connect to the database"); 

// Run query 

$sql="INSERT INTO teacher (name) values ('$fname')"; 
$dupesql = "SELECT * FROM table where (name = '$fname')";

$duperaw = mysql_query($dupesql);

if (mysql_num_rows($duberaw) > 0) {
  //your code ...
}
if (mysql_query($sql,$db)) 
{ 
        echo "The following Teacher"; 
        echo "<br>Record: $fname  has been added to          
        database.<p>"; 
} 
else 
{ 
        do_error("Failed to add record"); 
} 

function  do_error($error) 
{ 
        echo  $error; 
        die; 
} 

?>

Open in new window



Notice: Undefined variable: duberaw in C:\xampp\htdocs\insert.php on line 40
 
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\insert.php on line 40
 Failed to add record
0
Comment
Question by:paddy086
  • 2
3 Comments
 
LVL 42

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 334 total points
ID: 38859587
Line 29 says $duperaw
line 31 says $duberaw

check your spelling :)
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 166 total points
ID: 38859618
change line 29 to:
$duperaw = mysql_query($dupesql, $db);

Open in new window

0
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 334 total points
ID: 38859620
Line 26 is INSERTing from a table called 'teacher'
Line 27 is SELECTing from a table caled 'table'
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now