Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

duplication insert into SQL

Posted on 2013-02-06
3
293 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 43

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 43

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

860 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