Solved

duplication insert into SQL

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHPStorm debugging issues 1 45
php function to remove a file 31 39
Why do people dis php? 5 50
google analytics on wp-admin password protected area 2 23
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 dynamically set the form action using jQuery.

772 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